package com.zh.mediaservice.mapper;

import com.github.pagehelper.Page;
import com.zh.mediapojo.entity.Message;
import com.zh.mediapojo.vo.ChatVO;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.springframework.web.bind.annotation.PathVariable;

import java.time.LocalDateTime;
import java.util.List;

@Mapper
public interface MessageMapper {

    @Insert("insert into chat_record values (#{message1.sender},#{message1.receiver},#{message1.type},#{message1.content}" +
            ",#{message1.date},1,#{isUser})")
    void save(@Param("message1") Message message1, @Param("isUser") boolean isUser);

    void saveMessageList(@Param("messageList") List<Message> messageList, @Param("isUser") boolean isUser);


    @Select("select type,content,create_time as time,isUser from chat_record" +
            " where (sender=#{userId} and receiver=#{doctorId}) or" +
            "(sender=#{doctorId} and receiver=#{userId}) order by create_time ")
    Page<ChatVO> getHistoryChat(@Param("userId") Integer userId, @Param("doctorId") Integer doctorId);
}
